﻿using System;
using System.Windows.Forms;

using LCL.Tools.WinFrm.UserControls;

namespace LCL.Tools
{
    public partial class OptionFrm : BaseFrm
    {
        private MainFrm mainForm;
        private UcOptionsEnviroments optionsEnviroments;
        private UcDatatypeMap ucDatatype;
        private UcSysManage ucSysmanage;
        private UcAddIns ucAddIns;
        private UcNameConfig ucNameConfig;
        public OptionFrm(MainFrm mainform)
        {
            InitializeComponent();
            mainForm = mainform;
            optionsEnviroments = new UcOptionsEnviroments();
            this.ucDatatype = new UcDatatypeMap();
            this.ucDatatype.Dock = DockStyle.Fill;
            this.ucSysmanage = new UcSysManage();
            this.ucSysmanage.Dock = DockStyle.Fill;
            this.ucAddIns = new UcAddIns();
            this.ucAddIns.Dock = DockStyle.Fill;
            this.ucNameConfig = new UcNameConfig();
            this.ucNameConfig.Dock = DockStyle.Fill;
        }
        private void OptionFrm_Load(object sender, EventArgs e)
        {
            InitTreeView();
        }
        private void InitTreeView()
        {
            TreeNode treeNode = new TreeNode("环境", 0, 1);
            treeNode.Tag = "tnEnviroment";
            TreeNode treeNode2 = new TreeNode("代码生成设置", 0, 1);
            treeNode2.Tag = "tnCodeSet";
            TreeNode treeNode3 = new TreeNode("组件管理", 0, 1);
            treeNode3.Tag = "tnAddIn";
            TreeNode treeNode4 = new TreeNode("系统管理", 0, 1);
            treeNode4.Tag = "tnDbo";
            TreeNode treeNode10 = new TreeNode("字段类型映射", 2, 3);
            treeNode10.Tag = "tnDatatype";
            treeNode2.Nodes.Add(treeNode10);
            TreeNode treeNode11 = new TreeNode("名称设置", 2, 3);
            treeNode11.Tag = "tnConfig";
            treeNode2.Nodes.Add(treeNode11);

            this.treeView1.Nodes.Add(treeNode);
            this.treeView1.Nodes.Add(treeNode2);
            this.treeView1.Nodes.Add(treeNode3);
            this.treeView1.Nodes.Add(treeNode4);
            treeNode.Expand();
            treeNode2.Expand();
            this.UserControlContainer.Controls.Add(this.optionsEnviroments);
            this.UserControlContainer.Controls.Add(this.ucAddIns);
            this.UserControlContainer.Controls.Add(this.ucDatatype);
            this.UserControlContainer.Controls.Add(this.ucSysmanage);
            this.UserControlContainer.Controls.Add(this.ucNameConfig);
            this.ActivateOptionControl(this.optionsEnviroments);

        }
        private void ActivateOptionControl(System.Windows.Forms.UserControl optionControl)
        {
            foreach (UserControl uc in this.UserControlContainer.Controls)
                uc.Hide();
            optionControl.Show();
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selectedNode = this.treeView1.SelectedNode;
            if (selectedNode != null)
            {
                switch (selectedNode.Text)
                {
                    case "环境":
                        ActivateOptionControl(this.optionsEnviroments);
                        break;
                    case "字段类型映射":
                        ActivateOptionControl(this.ucDatatype);
                        break;
                    case "组件管理":
                        ActivateOptionControl(this.ucAddIns);
                        break;
                    case "系统管理":
                        ActivateOptionControl(this.ucSysmanage);
                        break;
                    case "名称设置":
                        ActivateOptionControl(this.ucNameConfig);
                        break;
                }
            }
        }
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            this.ucDatatype.SaveData();
            this.ucSysmanage.SaveDBO();
            this.ucNameConfig.SaveConfig();
            base.Close();
        }
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }
    }
}
